const express = require('express');
const router = express.Router()
const pool = require('../utils/pool.js')

// 城市列表接口
router.get('/allcities',(req,res,next)=>{
  const sql = 'select * from allcities'
  pool.query(sql,(err,r)=>{
    if(err){
      return next()
    }
    const data = r.map(v=>{
      const {id,indexes,city} = v
      return {
        id,
        indexes,
        city:JSON.parse(city)
      }
    })
    res.send( {code:200, msg:'ok',data})
  })
})



module.exports = router